﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SmartMovieTime
{
    class AtMovieAreaRow : ITxtTableRow
    {
        private const int IndexAreaName = 0;
        private const int IndexAreaId = 1;
        private const int IndexEnabled = 2;
        private string[] txtRow;

        public string AreaName
        {
            get
            {
                if (txtRow.Length >= IndexAreaName + 1)
                    return txtRow[IndexAreaName];
                else
                    return null;
            }
            
        }
        
        public string AreaId
        {
            get
            {
                if (txtRow.Length >= IndexAreaId + 1)
                    return txtRow[IndexAreaId];
                else
                    return null;
            }
        }

        public bool Enabled
        {
            get
            {
                if (txtRow.Length >= IndexEnabled + 1)
                {
                    return txtRow[IndexEnabled] == "1";
                }
                else
                {
                    return false;
                }
            }
        }

        public void LoadRow(string[] row)
        {
            txtRow = row;
        }
    }

    class AtMovieTheaterRow : ITxtTableRow
    {
        private string[] txtRow;
        private const int IndexSubArea = 0;
        private const int IndexTheaterName = 1;
        private const int IndexTheaterId = 2;

        public string TheaterName
        {
            get
            {
                if (txtRow.Length >= IndexTheaterName + 1)
                    return txtRow[IndexTheaterName];
                else
                    return null;
            }
        }

        public string SubareaName
        {
            get
            {
                if (txtRow.Length >= IndexSubArea + 1)
                    return txtRow[IndexSubArea];
                else
                    return null;
            }
        }

        public string TheaterId
        {
            get
            {
                if (txtRow.Length >= IndexTheaterId + 1)
                    return txtRow[IndexTheaterId];
                else
                    return null;
            }
        }

        public AtMovieTheaterRow()
        {
        }

        public void LoadRow(string[] row)
        {
            txtRow = row;
        }
    }

    class AtMovieMovieRow : ITxtTableRow
    {
        private string[] txtRow;
        private const int IndexMovieName = 0;
        private const int IndexTimeBegin = 1;

        public AtMovieMovieRow()
        {
        }

        public void LoadRow(string[] row)
        {
            txtRow = row;
        }

        public string MovieName
        {
            get
            {
                if (txtRow.Length >= IndexMovieName + 1)
                    return txtRow[IndexMovieName];
                else
                    return null;
            }
        }

        public string[] TimeList
        {
            get
            {
                if (txtRow.Length > 1)
                {
                    string[] timeList = new string[txtRow.Length - 1];
                    Array.Copy(txtRow, IndexTimeBegin, timeList, 0, txtRow.Length - 1);
                    return timeList;
                }
                else
                {
                    return null;
                }
            }
        }
    }
}
